package net.lab1024.sa.base.common.constant;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 公共配置的key
 */
public class SystemKeyConst {

    /* ############ 公共的上游单价key  ############ */
    /** 联通单价 */
    public static final String CUCC_PRICE = "CuccPrice";
    /** 电信单价 */
    public static final String CTCC_PRICE = "CtccPrice";
    /** 移动单价 */
    public static final String CMCC_PRICE = "CmccPrice";

    /** 配置对象词典 */
    private static final Map<String, Config> CONFIG_MAP = new HashMap<>();

    // 初始词典内容
    static {
        CONFIG_MAP.put(DefaultConfig.KEY_PREFIX, new DefaultConfig());
        CONFIG_MAP.put(PainetBoxConfig.KEY_PREFIX, new PainetBoxConfig());
    }

    /**
     * 是否包含前缀
     */
    public static Boolean containsPrefix(String prefix) {
        return CONFIG_MAP.containsKey(prefix);
    }

    /**
     * 根据前缀获取
     */
    public static Config getConfig(String prefix) {
        return CONFIG_MAP.get(prefix);
    }

    /** 配置接口 */
    public interface Config {
        /**
         * 是否包含key
         */
        Boolean containsAllKey(Collection<String> keys);
    }

    /**
     * 默认配置
     */
    public static class DefaultConfig implements Config {

        /** 前缀 */
        public static final String KEY_PREFIX = "default";

        /** 默认上游 */
        public static final String UPSTREAM = KEY_PREFIX + "Upstream";

        /** 相关KEY */
        public static final String[] KEYS = {
                UPSTREAM,
        };

        @Override
        public Boolean containsAllKey(Collection<String> keys) {
            return Arrays.asList(KEYS).containsAll(keys);
        }
    }

    /**
     * 上游配置-派盒子配置
     */
    public static class PainetBoxConfig implements Config {

        /** 前缀 */
        public static final String KEY_PREFIX = "painetBox";

        /** 账户 */
        public static final String ACCOUNT = KEY_PREFIX + "Account";

        /** ak */
        public static final String AK = KEY_PREFIX + "AK";

        /** as */
        public static final String AS = KEY_PREFIX + "AS";

        /** 接口服务地址 */
        public static final String SERVER_URL = KEY_PREFIX + "ServerUrl";

        /** 派盒子连通单价 */
        public static final String CUCC_PRICE = KEY_PREFIX + SystemKeyConst.CUCC_PRICE;

        /** 派盒子电信单价 */
        public static final String CTCC_PRICE = KEY_PREFIX + SystemKeyConst.CTCC_PRICE;

        /** 派盒子移动单价 */
        public static final String CMCC_PRICE = KEY_PREFIX + SystemKeyConst.CMCC_PRICE;

        /** 相关KEY */
        public static final String[] KEYS = {
                ACCOUNT,
                AK,
                AS,
                SERVER_URL,
                CUCC_PRICE,
                CTCC_PRICE,
                CMCC_PRICE,
        };

        @Override
        public Boolean containsAllKey(Collection<String> keys) {
            return Arrays.asList(KEYS).containsAll(keys);
        }
    }
}
